package com.ruoyi.product.controller;

import java.util.List;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.product.domain.ProductSpuSpecValue;
import com.ruoyi.product.service.IProductSpuSpecValueService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * SPU规格属性值Controller
 * 
 * @author liuhizhong
 * @date 2025-07-11
 */
@RestController
@RequestMapping("/product/productSpuSpecValue")
public class ProductSpuSpecValueController extends BaseController
{
    @Autowired
    private IProductSpuSpecValueService productSpuSpecValueService;

    /**
     * 查询SPU规格属性值列表
     */
    @PreAuthorize("@ss.hasPermi('product:productSpuSpecValue:list')")
    @GetMapping("/list")
    public TableDataInfo list(ProductSpuSpecValue productSpuSpecValue)
    {
        startPage();
        List<ProductSpuSpecValue> list = productSpuSpecValueService.selectProductSpuSpecValueList(productSpuSpecValue);
        return getDataTable(list);
    }

    /**
     * 导出SPU规格属性值列表
     */
    @PreAuthorize("@ss.hasPermi('product:productSpuSpecValue:export')")
    @Log(title = "SPU规格属性值", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProductSpuSpecValue productSpuSpecValue)
    {
        List<ProductSpuSpecValue> list = productSpuSpecValueService.selectProductSpuSpecValueList(productSpuSpecValue);
        ExcelUtil<ProductSpuSpecValue> util = new ExcelUtil<ProductSpuSpecValue>(ProductSpuSpecValue.class);
        util.exportExcel(response, list, "SPU规格属性值数据");
    }

    /**
     * 获取SPU规格属性值详细信息
     */
    @PreAuthorize("@ss.hasPermi('product:productSpuSpecValue:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(productSpuSpecValueService.selectProductSpuSpecValueById(id));
    }

    /**
     * 新增SPU规格属性值
     */
    @PreAuthorize("@ss.hasPermi('product:productSpuSpecValue:add')")
    @Log(title = "SPU规格属性值", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProductSpuSpecValue productSpuSpecValue)
    {
        return toAjax(productSpuSpecValueService.insertProductSpuSpecValue(productSpuSpecValue));
    }

    /**
     * 修改SPU规格属性值
     */
    @PreAuthorize("@ss.hasPermi('product:productSpuSpecValue:edit')")
    @Log(title = "SPU规格属性值", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProductSpuSpecValue productSpuSpecValue)
    {
        return toAjax(productSpuSpecValueService.updateProductSpuSpecValue(productSpuSpecValue));
    }

    /**
     * 删除SPU规格属性值
     */
    @PreAuthorize("@ss.hasPermi('product:productSpuSpecValue:remove')")
    @Log(title = "SPU规格属性值", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(productSpuSpecValueService.deleteProductSpuSpecValueByIds(ids));
    }
}
